package com.online.onlinestudent.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.online.onlinestudent.entity.Admin;
import com.online.onlinestudent.entity.Course;
import com.online.onlinestudent.entity.Teacher;
import com.online.onlinestudent.mapper.CourseMapper;
import com.online.onlinestudent.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> implements CourseService {

    @Autowired
    private CourseMapper courseMapper;

    @Override
    public List<Course> getCoursesByCategoryId(Long categoryId) {
        List<Course> courses = courseMapper.getCoursesByCategoryId(categoryId);
        return courses;
    }

    @Override
    public List<Course> getCoursesByTeacherId(Long id) {
        QueryWrapper<Course> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("teacher_id", id);
        List<Course> list=baseMapper.selectList(queryWrapper);
        if (list.isEmpty()||list==null){
            return new ArrayList<>();
        }
        return list;
    }

    @Override
    public List<Course> fuzzyQueryByTitle(String title) {
        QueryWrapper<Course> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("title", title);
        List<Course> list=baseMapper.selectList(queryWrapper);
        if (list.isEmpty()||list==null){
            return new ArrayList<>();
        }
        return list;
    }
}
